package com.my.control;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.my.bean.LiuYan;
import com.my.bean.Pic;
import com.my.bean.User;
import com.my.common.PageBean;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport implements RequestAware,
		SessionAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Map<String, Object> request;
	Map<String, Object> session;
	Integer pageNo;
	Pic pic;
	User user;
	LiuYan liuYan;

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Pic getPic() {
		return pic;
	}

	public void setPic(Pic pic) {
		this.pic = pic;
	}

	public LiuYan getLiuYan() {
		return liuYan;
	}

	public void setLiuYan(LiuYan liuYan) {
		this.liuYan = liuYan;
	}

	// 分页方法
	@SuppressWarnings("unchecked")
	public <T> PageBean<T> setPageBean(List<T> list, int totalRecords) {
		PageBean<T> pagebean = (PageBean<T>) request.get("pagebean");
		if (pagebean == null) {
			pagebean = new PageBean<T>();
			request.put("pagebean", pagebean);
		}
		pagebean.setPageNo(pageNo); // 设置当前页码
		pagebean.setPageSize(15);// 每页显示15个
		pagebean.setTotalRecords(totalRecords);
		pagebean.setList(list);
		return pagebean;
	}
}
